<!DOCTYPE HTML>
<html  lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-ecrCard-add" th:object="${ecrMerchant}">
			<div style="display: none;" id ="merIdDiv" th:text="${ecrMerchant.id}"></div>
			<div class="form-group" style="display: none;">	
				<div class="col-sm-8">
					<input th:value="${ecrMerchant.id}" id="merchantId" name="merchantId" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">卡号：</label>
				<div class="col-sm-8">
					<input id="bankAccount" name="bankAccount" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">持卡人：</label>
				<div class="col-sm-8">
					<input th:value="${ecrMerchant.name}" disabled="disabled" id="bankAccountName" name="bankAccountName" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">持卡人身份证号：</label>
				<div class="col-sm-8">
					<input th:value="${ecrMerchant.idCardNumber}" id="idCardNumber" name="idCardNumber" disabled="disabled" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">银行预留手机号：</label>
				<div class="col-sm-8">
					<input id="bankPhone" name="bankPhone" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">银行卡背面后三位：</label>
				<div class="col-sm-8">
					<input id="cvn" name="cvn" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">银行卡到期日期：</label>
				<div class="col-sm-8">
					<input id="expdate" name="expdate" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">额度：</label>
				<div class="col-sm-8">
					<input id="limitMoney" name="limitMoney" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">还款日：</label>
				<div class="col-sm-8">
					<input id="repaymentDay" name="repaymentDay" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">出账单日：</label>
				<div class="col-sm-8">
					<input id="billDay" name="billDay" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">备注：</label>
				<div class="col-sm-8">
					<input id="remark" name="remark" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group" id="invokeDiv" style="display: none;">
				<label class="col-sm-3 control-label">是否认证：</label>	
				<div class="col-sm-8">
					<div class="radio-box">
						<label>
							<input type="radio" value="0" th:id="type1" name="type" checked="checked"> 仍需认证
						</label>
					</div>
					<div class="radio-box">
						<label>
							<input type="radio" value="1" th:id="type2" name="type"> 无需认证
						</label>	
					</div>
				</div>
			</div>
		</form>
	</div>
    <div th:include="include::footer"></div>
    <script type="text/javascript">
		var prefix = ctx + "system/ecrCardForDLS"
		var merchantId = $("#merIdDiv").text();
		$("#form-ecrCard-add").validate({
			rules:{
				bankAccount:{
					required:true,
					digits:true,  //必须为数字
					minlength: 10,//最小长度
        			maxlength: 25 //最大长度
				},
				bankAccountName:{
					required:true,
					minlength: 2,//最小长度
					maxlength: 25 //最大长度
				},
				bankPhone:{
					required:true,
					digits:true,  //必须为数字
					isPhone:true
				},
				cvn:{
					required:true,
					digits:true,  //必须为数字
					minlength: 3,//最小长度
					maxlength: 3//最小长度
				},
				expdate:{
					required:true,
					digits:true,  //必须为数字
					minlength: 4,//最小长度
					maxlength: 4//最小长度
				},
				repaymentDay:{
					required:true,
					digits:true,  //必须为数字
					minlength: 1,//最小长度
					maxlength:2//最小长度
				},
				billDay:{
					required:true,
					digits:true,  //必须为数字
					minlength: 1,//最小长度
					maxlength:2//最小长度
				},
				limitMoney:{
					digits:true,  //必须为数字
					maxlength: 8//最大长度
				},
			}
		});
		
		function submitHandler() {
	        if ($.validate.form()) {
	        	var merchantId =$("#merchantId").val();
	          	var type = $('input[name="type"]:checked').val(); 
		       	  $.ajax({
		  		         url:prefix + "/add", //
		  		        dataType:"json",
		  		        type: "post",
		  		    	data:	{
		  	 		       	"merchantId":$("#merchantId").val(),
		  	 		       	"bankAccount":$("#bankAccount").val(),
		  	 		       	"bankAccountName":$("#bankAccountName").val(),
		  	 		       	"idCardNumber":$("#idCardNumber").val(),
		  	 		       	"bankPhone":$("#bankPhone").val(),
		  	 		       	"cvn":$("#cvn").val(),
		  	 		       	"expdate":$("#expdate").val(),
		  	 		       	"limitMoney":$("#limitMoney").val(),
		  	 		       	"billDay":$("#billDay").val(),
		  	 		       	"repaymentDay":$("#repaymentDay").val(),
		  	 		       	"remark":$("#remark").val(),
		  	 		       	"type":type
		  	 		       	},
		  		          success:function(re){
		  		        	//认证失败
		  		        	 if(re.code=="0"){
		 						$.modal.msgSuccess(re.msg);
		 						//刷新表格
		 						$.operate.successCallback(re);
		 					//实名验证未通过	
	 						}else if(re.code=="1"){
							 	$.modal.alertError(re.msg);
							 	//显示选择是否实名认证按钮
							 	$("#invokeDiv").show();
							 	return;
							}else if(re.code=="2"){
								$.modal.alertError(re.msg);
								return;
							}
			        } 
			   });
	        	
	        }
	    }
	</script>
</body>
</html>
